/**
 * 题三
 */

const fp = require('lodash/fp')
const {Maybe, Container} = require('./support')

// 练习1
let maybe = Maybe.of([5, 6, 1])
let ex1 = (n) => {
  return maybe.map(fp.map(fp.add(n)))
}
console.log('ex1 test:')
console.log(ex1(1)._value)
console.log('\n')

// 练习2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])
let ex2 = () => {
  return xs.map(fp.first)._value
}
console.log('ex2 test:')
console.log(ex2())
console.log('\n')

// 练习3
let safeProp = fp.curry(function (x,o) {
  return Maybe.of(o[x])
})
let user = {id: 2, name: 'Albert'}
let ex3 = () => {
  return safeProp('name')(user).map(fp.first)._value
}
console.log('ex3 test:')
console.log(ex3())
console.log('\n')

// 练习4
let ex4 = function (n) {
  return Maybe.of(n).map(parseInt)._value
}
console.log('ex4 test:')
console.log(ex4(null))
console.log(ex4('33'))
console.log('\n')
